package com.example.vae.Home.Home.dongtai;

import androidx.lifecycle.ViewModelProviders;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.vae.Adapter.HomeRecyclerViewAdapter;
import com.example.vae.Pojo.HomeInformation;
import com.example.vae.R;
import com.example.vae.XingwenViewModel;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;

public class xingwen extends Fragment {

    private XingwenViewModel mViewModel;
    private List<HomeInformation> list=new ArrayList<>();
    private RecyclerView recyclerView;
    private HomeRecyclerViewAdapter homeRecyclerViewAdapter;

    public static xingwen newInstance() {
        return new xingwen();
    }

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.xingwen_fragment, container, false);
        recyclerView=view.findViewById(R.id.re);
        mViewModel = ViewModelProviders.of(this).get(XingwenViewModel.class);
        // TODO: Use the ViewModel
        HomeInformation homeInformation;
        int [] draws={R.drawable.dongtai_1,R.drawable.dongtai_2,R.drawable.dongtai_3,R.drawable.dongtai_4};
        String []types={"视频","专访","图集","新闻"};
        for(int i=0;i<10;i++){
            homeInformation=new HomeInformation();
            homeInformation.setTitle("QQ标题"+i);
            homeInformation.setGood_number(new Random().nextInt(100)+1);
            homeInformation.setMes_number(new Random().nextInt(1000));
            homeInformation.setDate(new Date().toString());
            homeInformation.setItem_img(draws[i%4]);
            homeInformation.setItem_type(types[i%4]);
            homeInformation.setContext("这个是是测试的内容"+i);
            list.add(homeInformation);

        }

        homeRecyclerViewAdapter=new HomeRecyclerViewAdapter(getActivity(),list);

        recyclerView.setAdapter(homeRecyclerViewAdapter);
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

    }

}
